package com.zb.knowledge.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.SelectVo;
import com.zb.knowledge.service.ConKnowledgeTypeService;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjKnowledgeTypeService;
import com.zb.utils.TokenUtil;
import com.zb.vo.KnowledgeTypeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 知识库分类表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-11-13
 */
@Api(tags = "知识中心分类接口")
@RestController
@RequestMapping("/knowledge/type")
public class ZjKnowledgeTypeController {
    @Resource
    private ZjKnowledgeTypeService knowledgeTypeService;
    @Resource
    private ConKnowledgeTypeService conKnowledgeTypeService;

    @SystemLog(moduleType = OperationLogModuleType.KNOWLEDGE_MODULE_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "知识中心-知识库分类 - 新增或修改知识库分类")
    @ApiOperation("新增或修改知识库分类")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid KnowledgeTypeVo typeVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        knowledgeTypeService.save(custAccId, typeVo);
        return Result.success(null == typeVo.getId()? "新增分类成功" : "修改分类成功");
    }

    @ApiOperation("获取知识库分类列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取知识库分类列表成功").data(knowledgeTypeService.getList(custAccId, selectVo));
    }

    @ApiOperation("根据知识库分类ID获取详情")
    @GetMapping("/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "知识库分类ID", required = true) Long id) {
        return Result.success("获取详情成功").data(PageUtil.row(knowledgeTypeService.getDetail(id)));
    }

    @SystemLog(moduleType = OperationLogModuleType.KNOWLEDGE_MODULE_TYPE, type = OperationLogType.UPDATE, remark = "知识中心-知识库分类 - 批量启用或禁用知识库分类")
    @ApiOperation("批量启用或禁用知识库分类")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "知识库分类状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "知识库分类ID", required = true) List<Long> ids) {
        knowledgeTypeService.updateDisableBatchById(ids, status);
        return Result.success(status? "禁用分类成功" : "启用分类成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.KNOWLEDGE_MODULE_TYPE, type = OperationLogType.DELETE, remark = "知识中心-知识库分类 - 批量删除知识库分类")
    @ApiOperation("批量删除知识库分类")
    @DeleteMapping("/delete")
    public Result delete(@RequestBody @ApiParam(value = "知识库分类ID", required = true) List<Long> ids) {
        conKnowledgeTypeService.deleteBatchById(ids);
        return Result.success("删除知识库分类成功");
    }



}
